<?php

namespace App\Http\Controllers\Api;

use App\Model\AdminLog;
use App\Model\GeneralizeStatistics;
use App\Model\Number;
use App\Model\OperationLogs;
use App\Model\RedPacketSet;
use App\Model\RedPacketStream;
use App\Model\Room;
use App\Model\RoomVoiceCheckLogs;
use App\Model\SystemConfig;
use App\Model\VoiceAuditConfig;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;


class SystemController extends BaseController
{
    protected $model = null;

    public function __construct(Request $request, SystemConfig $systemConfig)
    {
        parent::__construct($request);
        $this->model = $systemConfig;
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        return $this->toJson(self::SUCCESS, $this->model->getList($request));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $validator = Validator::make($request->all(), [
            'key' => 'required|unique:api.system_config,key',
            'value' => 'nullable',
            'desc' => 'required',
            'type' => 'required', Rule::in(0, 1)
        ]);
        if ($validator->fails()) {
            return $this->toJson(self::PARAM_ERROR, [], $validator->errors()->all()[0]);
        }
        $data = $request->except('_url', 'token');
        $res = $this->model->createData($data);
        if ($res['code'] !== 0) {
            return $this->toJson(self::ERROR, $res);
        }
        $data['id'] = $res['data']['id'];
        OperationLogs::createData($request, OperationLogs::SYSTEM, '新增配置');
        return $this->toJson(self::SUCCESS, $data);
    }

    /**
     * Display the specified resource.
     *
     * @param int $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
    }

    /**
     * Update the specified resource in storage.
     *
     * @param \Illuminate\Http\Request $request
     * @param int $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $validator = Validator::make($request->all(), [
            'key' => 'required',
            'value' => 'nullable',
            'desc' => 'required',
            'type' => 'required', Rule::in(0, 1)
        ]);
        if ($validator->fails()) {
            return $this->toJson(self::PARAM_ERROR, [], $validator->errors()->all()[0]);
        }
        $res = $this->model->updateData($request->except(['_url', 'token']), $this->user);
        if ($res['code'] !== 0) {
            return $this->toJson(self::ERROR, $res);
        }
        OperationLogs::createData($request, OperationLogs::SYSTEM, '编辑配置', $id);
//        return $this->toJson(self::SUCCESS, $this->model->where(['id' => $id])->update($request->except('_url','token')));
        return $this->toJson(self::SUCCESS, $res);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param int $id
     * @return \Illuminate\Http\Response
     */
    public function destroy(Request $request, $id)
    {
        $res = $this->model->removeData(['id' => $id]);
        if ($res['code'] !== 0) {
            return $this->toJson(self::ERROR, $res);
        }
        OperationLogs::createData($request, OperationLogs::SYSTEM, '删除配置', $id);
        return $this->toJson(self::SUCCESS, $res);
    }

    /**
     * 提现现金次数
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function cashNumber(Request $request)
    {
        $number = $request->input('number');
        $res = curl_request(getKkaudioApiUrl() . '/inner/finance/withdraw/cash_number', ['number' => $number, 'operate_type' => 'write'], 'json', 'POST');
        if ($res['code'] == 0) {
            return $this->toJson(self::SUCCESS, $res['data']['result'], $res['msg']);
        }
        return $this->toJson(self::ERROR);
    }

    /**
     * 提现现金次数列表
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function cashNumberList(Request $request)
    {
        $number = $request->input('number');
        $res = curl_request(getKkaudioApiUrl() . '/inner/finance/withdraw/cash_number', ['number' => $number, 'operate_type' => 'read'], 'json', 'POST');
        if ($res['code'] == 0) {
            return $this->toJson(self::SUCCESS, $res['data']['result'], $res['msg']);
        }
        return $this->toJson(self::ERROR);
    }

    /**
     * 提现银行卡张数
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function bankNumber(Request $request)
    {
        $number = $request->input('number');
        $res = curl_request(getKkaudioApiUrl() . '/inner/finance/withdraw/bank_number', ['number' => $number, 'operate_type' => 'write'], 'json', 'POST');
        if ($res['code'] == 0) {
            return $this->toJson(self::SUCCESS, $res['data']['result'], $res['msg']);
        }
        return $this->toJson(self::ERROR);
    }

    public function bankNumberList(Request $request)
    {
        $number = $request->input('number');
        $res = curl_request(getKkaudioApiUrl() . '/inner/finance/withdraw/bank_number', ['number' => $number, 'operate_type' => 'read'], 'json', 'POST');
        if ($res['code'] == 0) {
            return $this->toJson(self::SUCCESS, $res['data']['result'], $res['msg']);
        }
        return $this->toJson(self::ERROR);
    }

    /**
     * 提现周期
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function week(Request $request)
    {
        $week = $request->input('week');
        $res = curl_request(getKkaudioApiUrl() . '/inner/finance/withdraw/week', ['week' => $week, 'operate_type' => 'write'], 'json', 'POST');
        if ($res['code'] == 0) {
            return $this->toJson(self::SUCCESS, $res['data']['result'], $res['msg']);
        }
        return $this->toJson(self::ERROR);
    }

    public function weekList(Request $request)
    {
        $res = curl_request(getKkaudioApiUrl() . '/inner/finance/withdraw/week', ['operate_type' => 'read'], 'json', 'POST');
        if ($res['code'] == 0) {
            return $this->toJson(self::SUCCESS, $res['data']['result'], $res['msg']);
        }
        return $this->toJson(self::ERROR);
    }

    /**
     * 提现例外用户
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function exceptionUser(Request $request, Number $numberModel)
    {
        $user_id = $request->input('user_id');
        $number = $request->input('number');
        $status = $request->input('status');
        $page = $request->input('page', 1);
        $limit = $request->input('limit', 10);
        $operate_type = $request->input('operate_type');

        $data = ['data' => [
            'user_id' => $user_id,
            'number' => $number,
            'operate_nickname' => $this->user->name,
            'status' => $status
        ], 'operate_type' => $operate_type];

        $res = curl_request(getKkaudioApiUrl() . '/inner/finance/withdraw/exception_user', $data, 'json', 'POST');

        $returnData = [];
        $total = 0;
        if ($res['code'] == 0) {
            if ($operate_type === 'read_all') {
                $user_ids = array_column($res['data']['result'], 'user_id');
                try {
                    $users = $numberModel->getNicknameByUserIds($user_ids);
                } catch (\Exception $e) {
                    return $this->toJson(self::SUCCESS);
                }
                $users = array_column($users, 'nickname', 'user_id');
                foreach ($res['data']['result'] as $item) {
                    array_push($returnData, array_merge($item, ['nickname' => $users[$item['user_id']]]));
                }
                $total = count($returnData);
                $returnData = collect($returnData)->forPage($page, $limit)->all();
            }
            return $this->toJson(self::SUCCESS, ['data' => $returnData, 'total' => $total], $res['msg']);
        }
        return $this->toJson(self::SUCCESS, [], $res['msg']);
    }

    public function exceptionUserStatus(Request $request, Number $numberModel)
    {
        $user_id = $request->input('user_id');
        $number = $request->input('number');
        $status = $request->input('status');
        $page = $request->input('page', 1);
        $limit = $request->input('limit', 10);
        $operate_type = $request->input('operate_type');

        $data = ['data' => [
            'user_id' => $user_id,
            'number' => $number,
            'operate_nickname' => $this->user->name,
            'status' => $status
        ], 'operate_type' => $operate_type];

        $res = curl_request(getKkaudioApiUrl() . '/inner/finance/withdraw/exception_user', $data, 'json', 'POST');

        $returnData = [];
        $total = 0;
        if ($res['code'] == 0) {
            if ($operate_type === 'read_all') {
                $user_ids = array_column($res['data']['result'], 'user_id');
                $users = $numberModel->getNicknameByUserIds($user_ids);
                $users = array_column($users, 'nickname', 'user_id');
                foreach ($res['data']['result'] as $item) {
                    array_push($returnData, array_merge($item, ['nickname' => $users[$item['user_id']]]));
                }
                $total = count($returnData);
                $returnData = collect($returnData)->forPage($page, $limit)->all();
            }
            return $this->toJson(self::SUCCESS, ['data' => $returnData, 'total' => $total], $res['msg']);
        }
        return $this->toJson(self::SUCCESS, [], $res['msg']);
    }

    public function exceptionUserList(Request $request, Number $numberModel)
    {
        $page = $request->input('page', 1);
        $limit = $request->input('limit', 10);
        $res = curl_request(getKkaudioApiUrl() . '/inner/finance/withdraw/exception_user', ['operate_type' => 'read_all'], 'json', 'POST');

        $returnData = [];
        if ($res['code'] == 0 && !empty($res['data']['result'])) {
            $user_ids = array_column($res['data']['result'], 'user_id');
            try {
                $users = $numberModel->getNicknameByUserIds($user_ids);
            } catch (\Exception $e) {
                return $this->toJson(self::SUCCESS);
            }
            $users = array_column($users, 'nickname', 'user_id');
            foreach ($res['data']['result'] as $item) {
                array_push($returnData, array_merge($item, ['nickname' => $users[$item['user_id']]]));
            }
            $total = count($returnData);
            $returnData = collect($returnData)->sortByDesc('timestamp')->forPage($page, $limit)->values()->all();
            return $this->toJson(self::SUCCESS, ['data' => $returnData, 'total' => $total], $res['msg']);
        }
        return $this->toJson(self::SUCCESS, [], $res['msg']);
    }

    /**
     * 语音审查 列表
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function voiceConfigAuditList(Request $request)
    {
        $model = new VoiceAuditConfig();
        return $this->toJson(self::SUCCESS, $model->getList($request));
    }

    public function getVoiceConfigCurrentState()
    {
        $res = curl_request(config('kkaudio.kkaudio_api') . '/inner/room/voice/check/get/config', '', 'urlencoded', 'GET');
        if ($res['code'] == 0) {
            return $this->toJson(self::SUCCESS, $res['data']);
        }
        return $this->toJson(self::ERROR);
    }

    /**
     * 语音审查 新增
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function voiceConfigAuditCreate(Request $request)
    {
        $model = new VoiceAuditConfig();
        $result = $model->createData($request->all());
        OperationLogs::createData($request, OperationLogs::SYSTEM, '新增语音审查');
        return $this->toJson(self::SUCCESS, $result);
    }

    /**
     * 语音审查 删除
     * @param $id   主键
     * @return \Illuminate\Http\JsonResponse
     */
    public function voiceConfigAuditDelete($id)
    {
        $model = new VoiceAuditConfig();
        $result = $model->deleteData($id);
        OperationLogs::createData(['id' => $id], OperationLogs::SYSTEM, '删除语音审查', $id);
        return $this->toJson(self::SUCCESS, $result);
    }

    /**
     * 语音审查 开启/停用
     * @param Request $request
     * @param $id
     * @return \Illuminate\Http\JsonResponse
     */
    public function voiceConfigAuditState(Request $request, $id)
    {
        $state = $request->input('state', 0);
        $model = VoiceAuditConfig::find($id);
        $model->state = $state;
        if ($state == 1) {
            $state = $model->check_model;
        }
        // 开启/关闭 间断检测、不间断检测、持续时间
        $curl_res = curl_request(config('kkaudio.kkaudio_api') . '/inner/room/voice/check/set/config', [
            'checkItems' => json_decode($model->check_items, true),
            'intervalTime' => $model->interval_time,
            'duration' => $model->continue_time,
            'state' => $state
        ], 'json', 'POST');
        if ($curl_res['code'] === 0) {
            $model->save();
            if ($state == 1) VoiceAuditConfig::where('id', '!=', $id)->update(['state' => 0]);
            OperationLogs::createData($request, OperationLogs::SYSTEM, '启停语音审查', $state);
            return $this->toJson(self::SUCCESS);
        }
        return $this->toJson(self::ERROR);
    }

    public function roomVoiceCheckLogsList(Request $request, RoomVoiceCheckLogs $roomVoiceCheckLogs)
    {
        return $this->toJson(self::SUCCESS, $roomVoiceCheckLogs->getList($request));
    }

    public function statisticsIosList(Request $request, GeneralizeStatistics $generalizeStatistics)
    {
        return $this->toJson(self::SUCCESS, $generalizeStatistics->getList($request));
    }

    /**
     * 红包方案列表
     * @param Request $request
     * @param RedPacketSet $redPacketSet
     * @return \Illuminate\Http\JsonResponse
     */
    public function getRedPacketSetList(Request $request, RedPacketSet $redPacketSet)
    {
        return $this->toJson(self::SUCCESS, $redPacketSet->getList($request));
    }

    /**
     * 创建红包方案
     * @param Request $request
     * @param RedPacketSet $redPacketSet
     * @return \Illuminate\Http\JsonResponse
     */
    public function createRedPacket(Request $request, RedPacketSet $redPacketSet)
    {
        $data = [
            'packet_name' => $request->input('packet_name'),
            'room_id' => $request->input('room_id'),
            'total_value' => $request->input('total_value'),
            'minute' => $request->input('minute'),
            'coin_type' => $request->input('coin_type'),
            'room_type' => $request->input('room_type'),
            'all_num' => $request->input('all_num')
        ];
        $res = $redPacketSet->createData($data);
        OperationLogs::createData($request, OperationLogs::SYSTEM, '创建红包方案');
        if ($res['code'] === 0) {
            return $this->toJson(self::SUCCESS);
        } else {
            return $this->toJson(self::ERROR, [], $res['msg']);
        }
    }

    /**
     * 红包方案开关
     * @param Request $request
     * @param RedPacketSet $redPacketSet
     * @return \Illuminate\Http\JsonResponse
     */
    public function switchRedPacket(Request $request, RedPacketSet $redPacketSet)
    {
        $res = $redPacketSet->switchRed(['status' => (int)$request->input('status')]);
        OperationLogs::createData($request, OperationLogs::SYSTEM, '红包方案开关', $request->input('status'));
        if ($res['code'] === 0) {
            return $this->toJson(self::SUCCESS);
        } else {
            return $this->toJson(self::ERROR, [], $res['msg']);
        }
    }

    /**
     * 红包明细
     * @param Request $request
     * @param $packet_id
     * @param RedPacketStream $redPacketStream
     * @return \Illuminate\Http\JsonResponse
     */
    public function getRedPacketStreamList(Request $request, $packet_id, RedPacketStream $redPacketStream)
    {
        return $this->toJson(self::SUCCESS, $redPacketStream->getList($request, $packet_id));
    }

    /**
     * 获取红包开关状态
     * @param RedPacketSet $redPacketSet
     * @return \Illuminate\Http\JsonResponse
     */
    public function getRedPacketStatus(RedPacketSet $redPacketSet)
    {
        return $this->toJson(self::SUCCESS, $redPacketSet->getSwitchStatus());
    }

    /**
     * 动态生成 HTML 活动,暂时未用
     * @param Request $request
     */
    public function generateHtml(Request $request)
    {

        $path = App::basePath() . DIRECTORY_SEPARATOR . "public" . DIRECTORY_SEPARATOR . "html";
        if (!is_dir($path)) {
            mkdir($path, 0777);
        }

        $htmlPath = $path . '/active.html';
        $image = $request->input('image');
        $title = $request->input('url');
        $html = <<<EOT
 <!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>$title</title>
  <style>
    body {
      padding: 0;
      margin: 0;
    }
  </style>
</head>

<body>
  <div id="main">
    <img src="$image" alt="" width="100%">
  </div>
</body>

</html>
EOT;
        file_put_contents($htmlPath, $html);
    }

    /**
     * 下载生成的 HTML 活动页，暂时未用
     */
    public function downloadHtml()
    {
        $filename = App::basePath() . DIRECTORY_SEPARATOR . "public" . DIRECTORY_SEPARATOR . "html" . DIRECTORY_SEPARATOR . 'active.html';
        header('Content-Type:text/html');
        header('Content-Disposition: attachment; filename="active.html"');
        header('Content-Length:' . filesize($filename));

        readfile($filename);
    }


    public function updateVoiceLogStatus(Request $request)
    {
        $data['id'] = $request->input('id') ?? 0;
        $data['status'] = $request->input('status') ?? 0;
        $res = curl_request(getKkaudioApiUrl() . '/inner/room/voice/check/log/edit', $data, 'json', 'POST');
        if ($res['code'] === 0) {
            return $this->toJson(self::SUCCESS);
        } else {
            return $this->toJson(self::ERROR, [], $res['msg']);
        }
    }

    public function zfbUserList(Request $request, Number $number)
    {
        $uuid = $request->input('uuid');
        $data = [];
        if (empty($uuid)) {
            $res = curl_request(getKkaudioApiUrl() . '/inner/finance/alipayh5white/get', [], 'urlencoded', 'GET');
            if ($res['code'] !== 0) {
                return $this->toJson(self::ERROR, [], $res['msg']);
            }
        } else {
            $user_info = $number->getInfoByUserId($uuid);
            $user_id = $user_info['user_id'] ?? 0;
            $res = curl_request(getKkaudioApiUrl() . '/inner/finance/alipayh5white/find', ['user_id' => $user_id], 'urlencoded', 'GET');
            if ($res['code'] !== 0) {
                return $this->toJson(self::ERROR, [], $res['msg']);
            }
        }
        $data = $res['data'];
        if (empty($data)) {
            return $this->toJson(self::ERROR, [], '暂无数据');
        }
        $list = $number->getNicknameUUidByUserIds($data);
        return $this->toJson(self::SUCCESS, $list);
    }

    public function zfbUserCreate(Request $request)
    {
        $user_id = $request->input('user_id');
        $res = curl_request(getKkaudioApiUrl() . '/inner/finance/alipayh5white/add', ['user_id' => $user_id], 'urlencoded', 'GET');
        if ($res['code'] === 0) {
            return $this->toJson(self::SUCCESS);
        } else {
            return $this->toJson(self::ERROR, [], $res['msg']);
        }
    }

    public function zfbUserDelete(Request $request)
    {
        $user_id = $request->input('user_id');
        $res = curl_request(getKkaudioApiUrl() . '/inner/finance/alipayh5white/del', ['user_id' => $user_id], 'urlencoded', 'GET');
        if ($res['code'] === 0) {
            return $this->toJson(self::SUCCESS);
        } else {
            return $this->toJson(self::ERROR, [], $res['msg']);
        }
    }

    /**
     * 渠道调房间配置
     *
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function setChannelRoom(Request $request)
    {
        $channel_id = $request->input('channel_id') ?? '';
        $room_id = $request->input('room_id') ?? '';
        $data = ['channel_no' => $channel_id, 'room_id' => $room_id];
        $res = curl_request(getKkaudioApiUrl() . '/system/channel/set_room_cms', $data, 'urlencoded', 'GET');

        OperationLogs::createData($request, OperationLogs::SYSTEM, '渠道调房间配置');

        if ($res['code'] === 0) {
            return $this->toJson(self::SUCCESS, $res['data']);
        } else {
            return $this->toJson(self::ERROR, [], $res['msg']);
        }
    }

    /**
     * 获取渠道跳房间列表
     *
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function getChannelRoomList(Request $request)
    {
        $res = curl_request(getKkaudioApiUrl() . '/system/channel/room_list', [], 'urlencoded', 'GET');
        $channelRoom = [];
        if ($res['data']) {
            foreach ($res['data'] as $channel_id => $room_id) {
                $channelRoom[] = [
                    'channel_id' => $channel_id,
                    'room_id' => $room_id,
                    'room_uid' => implode(',', Room::query()->select(['room_uid'])->whereIn('room_id', explode(',', $room_id))->pluck('room_uid')->toArray()),
                ];
            }
        }

        if ($res['code'] === 0) {
            return $this->toJson(self::SUCCESS, $channelRoom);
        } else {
            return $this->toJson(self::ERROR, [], $res['msg']);
        }
    }

    /**
     * 删除渠道跳房间记录
     *
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delChannelRoom(Request $request)
    {
        $res = curl_request(getKkaudioApiUrl() . '/system/channel/del_room', ['channel_no' => $request->input('channel_id')], 'urlencoded', 'GET');
        OperationLogs::createData($request, OperationLogs::SYSTEM, '删除渠道跳房间记录', $request->input('channel_id'));

        if ($res['code'] === 0) {
            return $this->toJson(self::SUCCESS, $res['data']);
        } else {
            return $this->toJson(self::ERROR, [], $res['msg']);
        }
    }

    public function setNavMenu(Request $request)
    {
        $id = $request->input('id') ?? '';
        $value = $request->input('value') ?? '';
        if (!$id || !$value) {
            return $this->toJson(self::ERROR, [], '参数错误');

        }
        $navData = $this->model->navList();
        $navData = array_column($navData, null, 'id');
        $data = [
            'key' => $navData[$id]['key'],
            'value' => $value
        ];
        $res = curl_request(getKkaudioApiUrl() . '/inner/nav/setNavMenu', $data, 'json', 'POST');
        if ($res['code'] === 0) {
            return $this->toJson(self::SUCCESS, $res['data']);
        } else {
            return $this->toJson(self::ERROR, [], $res['msg']);
        }
    }

    public function navList()
    {
        $data = $this->model->getNavList();
        $data = array_column($data, null, 'key');
        $navData = $this->model->navList();
        $navData = array_column($navData, null, 'key');
        foreach ($navData as $key => $val) {
            $navData[$key]['value'] = isset($data[$key]) ? $data[$key]['value'] : '';
            $navData[$key]['updated_at'] = isset($data[$key]) ? date('Y-m-d H:i:s', $data[$key]['updated_at']) : '';
        }
        return $this->toJson(self::SUCCESS, array_values($navData));
    }

    public function delNavMenu(Request $request)
    {
        $ids = $request->input('id') ?? '';
        if (!$ids) {
            return $this->toJson(self::ERROR, [], '参数错误');
        }
        $keys = $this->model->navList();
        $keys = array_column($keys, 'key', 'id');
        $idArr = explode(',', $ids);
        $dataIds = [];
        foreach ($idArr as $id) {
            $data = $this->model->getNavByKey($keys[$id]);
            array_push($dataIds, $data['id']);
        }

        $res = curl_request(getKkaudioApiUrl() . '/inner/nav/delNavMenu', ['id' => implode(',', $dataIds)], 'json', 'POST');
        if ($res['code'] === 0) {
            return $this->toJson(self::SUCCESS, $res['data']);
        } else {
            return $this->toJson(self::ERROR, [], $res['msg']);
        }
    }

    //快捷语列表
    public function listShortcutWord(Request $request)
    {
        return $this->toJson(self::SUCCESS, $this->model->listShortcutWord($request));
    }

    //添加快捷语
    public function addShortcutWord(Request $request)
    {
        $res = $this->model->addShortcutWord($request->all());
        if ($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::SYSTEM, '添加快捷语');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //编辑快捷语
    public function editShortcutWord(Request $request)
    {
        $res = $this->model->editShortcutWord($request->all());
        if ($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::SYSTEM, '编辑快捷语');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //删除快捷语
    public function delShortcutWord(Request $request)
    {
        $res = $this->model->delShortcutWord($request->all());
        if ($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::SYSTEM, '删除快捷语');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //黑名单语言列表
    public function listBlackWord(Request $request)
    {
        return $this->toJson(self::SUCCESS, $this->model->listBlackWord($request));
    }

    //添加黑名单语言
    public function addBlackWord(Request $request)
    {
        $res = $this->model->addBlackWord($request->all(), $this->user);
        if ($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::SYSTEM, '添加黑名单语言');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //编辑黑名单语言
    public function editBlackWord(Request $request)
    {
        $res = $this->model->editBlackWord($request->all(), $this->user);
        if ($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::SYSTEM, '编辑黑名单语言');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //删除黑名单语言
    public function delBlackWord(Request $request)
    {
        $res = $this->model->delBlackWord($request->all(), $this->user);
        if ($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::SYSTEM, '删除黑名单语言');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    public function updateGameRules(Request $request)
    {
        $data = $request->all();
        $res = curl_request(getKkaudioApiUrl() . '/inner/system/updateGameRule', $data, 'json', 'POST');
//        dd($res);
        return $this->toJson($res['code'], [], $res['msg']);
    }
    public function getGameRule(Request $request)
    {
        $data = $request->all();
        $res = curl_request(getKkaudioApiUrl() . '/inner/system/getGameRule', $data, 'json', 'POST');
//        dd($res);
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

}
